/** Created by CUIJA on 05-19-2017.*/

ordersService.$inject = ['$http'];

function ordersService($http) {

  var osc = this;

   function  orderlist(icnum,callback){
     var request = {
                method: 'get',
                url: '/m/order/getOrderByMerchant/'+icnum,
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }

   function  unreceivedOrderlist(icnum,callback){
     var request = {
                method: 'get',
                url: '/m/order/getUnreceivedOrder/'+icnum,
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }

   function  receivedOrderlist(icnum,callback){
     var request = {
                method: 'get',
                url: '/m/order/getReceivedOrder/'+icnum,
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }

   function  refusedOrderlist(icnum,callback){
     var request = {
                method: 'get',
                url: '/m/order/getRefusedOrder/'+icnum,
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }

   function  deliveringOrderlist(icnum,callback){
     var request = {
                method: 'get',
                url: '/m/order/getDeliveringOrder/'+icnum,
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }


   function  finishedOrderlist(icnum,callback){
     var request = {
                method: 'get',
                url: '/m/order/getFinishedOrder/'+icnum,
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }

   function receiveOrder(order,callback){
     var request = {
                method: 'post',
                url: '/m/order/receiveOrder',
                data: order
            };
            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }


   function refuseOrder(order,callback){
     var request = {
                method: 'post',
                url: '/m/order/refuseOrder',
                data: order
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }

   function deliverOrder(order,callback){
     var request = {
                method: 'post',
                url: '/m/order/deliverOrder',
                data: order
            };

            return $http(request).then(function(res, status, headers) {
              console.log(res.data);
                callback(null, res.data);
            });
   }



  return {
   orderlist : orderlist,
   unreceivedOrderlist : unreceivedOrderlist,
   receivedOrderlist : receivedOrderlist,
   refusedOrderlist : refusedOrderlist,
   deliveringOrderlist : deliveringOrderlist,
   finishedOrderlist : finishedOrderlist,
   receiveOrder : receiveOrder,
   refuseOrder : refuseOrder,
   deliverOrder : deliverOrder
  };

}


module.exports = ordersService;